package com.example.ui.util;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.util.*;

public class LYG2Utile {

    public static void main(String[] args) {
        mergeResult();
    }

    public static void mergeResult() {
        ExcelReader reader = ExcelUtil.getReader("D:/TESTS/merge.xlsx");
        HashMap<String, String> map = new HashMap<>(32);
        List<Map<String, Object>> readAll = reader.readAll();
        for (Map<String, Object> stringObjectMap : readAll) {
            String name = (String) stringObjectMap.get("病种");
            String result = (String) stringObjectMap.get("chatGPT结果");
            if (Objects.isNull(map.get(name))) {
                map.put(name, result);
            } else {
                map.put(name, map.get(name) + result);
            }
        }
        System.out.println("字符拼接完毕");
        System.out.println("map结果：" + map);
        reader.close();
        ExcelWriter writer = ExcelUtil.getWriter("D:/TESTS/result.xlsx");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String result = OpenUtils.templateD(entry.getValue(), entry.getKey());
            Map<String, Object> row1 = new LinkedHashMap<>();
            row1.put("病种", entry.getKey());
            row1.put("gpt结果", result);
            ArrayList<Map<String, Object>> rows = CollUtil.newArrayList(row1);
            writer.write(rows);
            writer.flush();
            System.out.println("写入excel。。。");
        }
        writer.close();

    }
}
